<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%--<script src="${pageContext.request.contextPath}/js/prototype.js" type="text/javascript"></script>--%>
    <%--<script src="${pageContext.request.contextPath}/js/effects.js" type="text/javascript"></script>--%>
    <%--<script type="text/javascript" src="${pageContext.request.contextPath}/js/validation.js"></script>--%>
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.java1234.com/jquery-easyui-1.3.3/demo/demo.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="http://www.java1234.com/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>

        <script type="text/javascript">

        function setActiveStyleSheet(title) {
            var i, a, main;
            for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
                if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
                    a.disabled = true;
                    if(a.getAttribute("title") == title) a.disabled = false;
                }
            }
        }
    </script>
    <link title="style1" rel="stylesheet" href="${pageContext.request.contextPath}/css/add_course.css" type="text/css" />
        <%@ include file= "index_nav.jsp" %>
</head>
<body>


<div class="form_content">
    <div id="test">

        <fieldset>
            <legend>录入课程</legend>

            <div class="form-row">
                <div class="field-label"><label for="sname">学生姓名</label>:</div>
                <div class="field-widget"><input name="sname" id="sname" class="required" title="Enter your name"/>
                </div>
            </div>

            <div class="form-row">
                <div class="field-label"><label for="sid">学号</label>:</div>
                <div class="field-widget"><input name="sid" id="sid" class="required validate-email"
                                                 title="Enter your name"/></div>
            </div>
            <div class="form-row">
                <div class="field-label"><label for="sex">性别</label>:</div>
                <div class="field-widget">
                    <select class="required validate-email" id="sex">

                        <option value="女">女</option>

                        <option selected value="男">男</option>

                    </select>
                </div>
            </div>


            <div class="form-row">
                <div class="field-label"><label for="major">专业</label>:</div>
                <div class="field-widget">
                    <select id="major" name="major" class="validate-selection" title="Choose your department">
                        <c:forEach var="major" items="${majors}" varStatus="trow">
                            <option value="${major.major_name}"
                                    major_id="${major.major_id}">${major.major_name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>

            <div class="form-row">
                <div class="field-label"><label for="max_num">最大选课数量</label>:</div>
                <div class="field-widget"><input name="max_num" id="max_num" class="required validate-password"
                                                 title="Enter a password greater than 6 characters"/></div>
            </div>
            <div class="form-row">
                <div class="field-label"><label for="birthday">出生日期</label>:</div>
                <div class="field-widget"><input name="birthday" value="1996-9-8" type="text" id="birthday" required
                                                 class="easyui-datebox required validate-password"
                                                 title="Enter a password greater than 6 characters"/></div>
            </div>

        </fieldset>

        <input type="submit" class="submit" value="提交"/> <input class="reset" type="button" value="重置"
                                                                onclick="valid.reset(); return false"/>
    </div>
</div>
<script type="text/javascript">
    (function () {
        function sendReq() {
            var msg = {};
            var sname = $('#sname').val();
            var sid = $('#sid').val();
            var sex = $('#sex option:selected').val();
            var major_id = $('#major option:selected').attr('major_id');
            var max_num = $('#max_num').val();
            var birthday = $('#birthday').val();
            msg.sname = sname;
            msg.sid = sid;
            msg.sex = sex;
            msg.major_id = major_id;
            msg.max_num = max_num;
            msg.birthday = birthday;
            console.log(msg);
            $.ajax({
                url: '${pageContext.request.contextPath}/admin/add_student',
                data: msg,
                dataType: "text",
                success: function (data) {
                    if (data == "success") {
                        alert("添加成功!")
                    }
                    else {
                        alert('添加失败!')
                    }
                }
            })
        }

        $('.submit').click(sendReq);
    })()
    /*function formCallback(result, form) {
        window.status = "valiation callback for form '" + form.id + "': result = " + result;
    }

    var valid = new Validation('test', {immediate : true, onFormValidate : formCallback});
    Validation.addAllThese([
        ['validate-password', '> 6 characters', {
            minLength : 7,
            notOneOf : ['password','PASSWORD','1234567','0123456'],
            notEqualToField : 'field1'
        }],
        ['validate-password-confirm', 'please try again.', {
            equalToField : 'field8'
        }]
    ]);*/
</script>

</body>
</html>